<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div class="" style="padding: 5px;"> 
	<button id="id-btn-dati" class="btn btn-sm btn-primary">开始答题</button> 
</div>
<table class="table table-striped table-hover table-bordered">
		  <thead>
			<tr id="sys_sys_TestPaper_table_title">
			  <th  width="50">编号</th>   
			  <th  width="20" fname="sys_TestPaperNameCheckBox"><input id="sys_TestPaperNameCheckBox" type="checkbox"></th>
			  <th  width="60" fname="name">卷名称</th> 
			  <!--<th  width="60" fname="note">卷描述</th> 后台查询中将juanID放在这一列上了-->
			  <th  width="50" fname="type">卷类型</th> 
			  <th  width="100" fname="showStartTime">开始时间</th> 
			  <th  width="100" fname="showEndTime">结束时间</th> 
			  <th  width="60" fname="string1">姓名</th> 
			  <!--<th  width="100" fname="string2">ID</th> -->
			  <th  width="60" fname="string3">完成时间</th>  
			  <th  width="60" fname="pValue">分值</th> 
			  <th  width="40" fname="string4">完成状态</th> 
			  <th  width="40" fname="desc">批改状态</th>  			  
			  <!-- 后台的查询是把三个元素放在了string1,2,3中 -->
			</tr>
		  </thead>
		  <tbody id="sys_sys_TestPaper_table">
			 
		  </tbody>
</table> 

<script>
(function(){
	
	//改变头像 和性别，还有类型
	function changeTestType(){ 
		
		var allstate =$("div[name='sys_sys_TestPaper_table_type_tr_td']");
		for(var i=0;i<allstate.length;i++){
			var bc = $(allstate[i]);
			if(bc.text()==1){
				bc.html('<font color="green">固定时间</font>');
			}else if(bc.text()==0){
				bc.html('<font color="red">规定时间</font>');
			}
		} 
		var allstate =$("div[name='sys_sys_TestPaper_table_desc_tr_td']");
		for(var i=0;i<allstate.length;i++){
			var bc = $(allstate[i]);
			if(bc.text()==1){
				bc.html('<font color="green">已阅</font>');
			}else if(bc.text()==0){
				bc.html('<font color="red">未阅</font>');
			}
		} 
		var allstate =$("div[name='sys_sys_TestPaper_table_string4_tr_td']");
		for(var i=0;i<allstate.length;i++){
			var bc = $(allstate[i]);
			if(bc.text()==1){
				bc.html('<font color="green">已完成作业</font>');
			}else if(bc.text()==0){
				bc.html('<font color="red">未完成作业</font>');
			}
		} 
	};
	//全选中事件
	$("#sys_TestPaperNameCheckBox").click(function(){
		var allc =$("[name=sys_sys_TestPaper_table_checkbox]");
		for(var i=0;i<allc.length;i++){
			$(allc[i])[0].checked=$(this)[0].checked;
		}
			 
	});

	//改变他的启用禁用的状态
	function changeUserState(){ 
		$("#sys_sys_TestPaper_table").children().click(function(){
			 /*
			 var allc =$("[name=sys_sys_TestPaper_table_checkbox]");
			 if(allc.length>0){
				 for(var i=0;i<allc.length;i++){
					 $(allc[i])[0].checked =false;
				 }
			 }*/
			if($(this).find("[name=sys_sys_TestPaper_table_checkbox]")[0].checked==true){
				$(this).find("[name=sys_sys_TestPaper_table_checkbox]")[0].checked=false;
			}else{
				$(this).find("[name=sys_sys_TestPaper_table_checkbox]")[0].checked=true;
				var table_id =$(this).attr("id");
			 
				//调用显示题的功能
			}
		});
	};
	//用户搜索
	function loadTestPaper(event,data){
		if(typeof(data)=="undefined"){
			data={};
		}
		var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=getHomeWorkComplet";
		data.name=$("#serch_text").val(); 
		var cp =$("#sys_TestPaper_pagination").find(".active");
		data.start=1;
		data.limit=20;
		if(cp.length>0){
			var ccp=$(cp[0]).text();
			if(parseInt(ccp)){
				data.start=ccp;
			}
		}  
		$("#table_TestPaper").wgrid({
					table_title:"sys_sys_TestPaper_table_title",
					tbodyId:"sys_sys_TestPaper_table",
					pagination:"sys_TestPaper_pagination",
					url:url,
					checkbox:true,
					data:data,
					success:function(){
							changeTestType();
							changeUserState();
					}
		});
	};
	//答题
	$("#id-btn-dati").click(function(e){ 
			e.preventDefault();
			var allc =$("input[type=checkbox][name=sys_sys_TestPaper_table_checkbox]:checked");
			if(allc.length>1||allc.length<=0){
				alert("你没有选中卷");
				return;
			}
			var table_id=$(allc[0]).parent().parent().attr("id");
			var cdata =$("#"+table_id).data(table_id); //这里的后台查询放的可是user_testpaper
			
			if(cdata.string4 =="1"){
				alert("你已经完成此作业的提交!");
				return ;
			} 
			$("#user_include").html("");
			$("#user_include").load("${pageContext.request.contextPath}/homeWork_QuestionInfo.jsp?r="+Math.random(),cdata,function(){
				var dialog = $("#dialog-message").removeClass('hide').dialog({
					modal: true,
					title: "答题",
					width:800,
					height:600,
					close:function(){
						$(this).dialog('destroy'); 
						$("#user_include").html("");
					},
					title_html: true,
					buttons: [  
						{
							text: "完成答题",
							"class" : "btn btn-primary btn-xs",
							click: function() { 
								 window.homeWork_QuestionInfo.completTestPaper(this);
							} 
						}
					]
				}); 
			});
		
	});
	$(function(){
		loadTestPaper(null,{});
	});
})();
</script>


 